//
//  TCLYHomeModel.m
//  YuErmuYing
//
//  Created by LYang on 16/9/2.
//  Copyright © 2016年 Tiancheng. All rights reserved.
//

#import "TCLYHomeModel.h"
#import "HttpRequest.h"

@implementation TCLYHomeModel
-(void) loadHomeImage{
    self.btnImageArr = [NSMutableArray arrayWithObjects: @"", @"", @"", @"", @"", @"", @"", @"", @"", nil];
}
/**---------------------------积分商城---------------------------**/
//积分商城首页的接口

-(void)loadHome{
    NSString * urlStr = @"http://112.74.114.1/parenting/Api/Integral/index";
    HttpRequest * httpRequest = [HttpRequest sharedInstance];
    [httpRequest postWithURLString:urlStr parameters:nil success:^(id responseObject) {
        id json = [NSJSONSerialization JSONObjectWithData:responseObject options:0 error:nil];
        self.homeBtnArr = json[@"data"][@"classify"];
        self.goodsArr = json[@"data"][@"goods"];
        self.advertisingArr = json[@"data"][@"carousel"];
        NSLog(@"%@",json[@"data"]);
        [[NSNotificationCenter defaultCenter] postNotificationName:@"loadIntegral" object:self];
    } failure:^(NSError *error) {
        NSLog(@"%@",error);
    }];
}
//积分商城所有的商品的接口（分类别哦）
-(void)loadIntegralAllGoodsParameter:(NSDictionary *)parameter{
    NSString * urlStr = @"http://112.74.114.1/parenting/Api/Integral/find_all";
    HttpRequest * httpRequest = [HttpRequest sharedInstance];
    [httpRequest postWithURLString:urlStr parameters:parameter success:^(id responseObject) {
        id json = [NSJSONSerialization JSONObjectWithData:responseObject options:0 error:nil];
        self.integralGoodsArr = json[@"data"];
        [[NSNotificationCenter defaultCenter] postNotificationName:@"loadIntegralGoods" object:self];
    } failure:^(NSError *error) {
        NSLog(@"%@",error);
    }];
}
//加载积分商城个别商品详细信息的接口
-(void)loadDetailedParameter:(NSDictionary *)parameter{
    NSString * urlStr = @"http://112.74.114.1/parenting/Api/Integral/detail";
    HttpRequest * httpRequest = [HttpRequest sharedInstance];
    [httpRequest postWithURLString:urlStr parameters:parameter success:^(id responseObject) {
        id json = [NSJSONSerialization JSONObjectWithData:responseObject options:0 error:nil];
        self.integralDetailedDic = json[@"data"][@"goods"];
        self.integralCarouselArr = json[@"data"][@"goods"][@"carousel_pic"];
        self.integralStandardArr = json[@"data"][@"goods"][@"standard_pic"];
        self.integralProductArr = json[@"data"][@"goods"][@"product_pic"];
        self.integralCommentArr = json[@"data"][@"comment"];
        self.integralCommentNumDic = json[@"data"][@"comment_num"];
        [[NSNotificationCenter defaultCenter] postNotificationName:@"loadIntegralDetailed" object:self];
    } failure:^(NSError *error) {
        NSLog(@"%@",error);
    }];
}
//加载积分商城确认订单的接口
-(void)loadSubmitOrderParameter:(NSDictionary *)parameter{
    NSString * urlStr = @"http://112.74.114.1/parenting/Api/Integral/enter_change";
    HttpRequest * httpRequest = [HttpRequest sharedInstance];
    [httpRequest postWithURLString:urlStr parameters:parameter success:^(id responseObject) {
        id json = [NSJSONSerialization JSONObjectWithData:responseObject options:0 error:nil];
        self.integralAdderssDic = json[@"data"][@"address"];
        self.integralOrderDic = json[@"data"][@"goods_info"];
        NSLog(@"积分商城%@",json);
        [[NSNotificationCenter defaultCenter] postNotificationName:@"loadIntegralOrder" object:self];
    } failure:^(NSError *error) {
        NSLog(@"%@",error);
    }];
}
//积分商城确认订单获取地址接口
-(void)loadIntegralAddressParameter:(NSDictionary *)parameter{
    NSString * urlStr = @"http://112.74.114.1/parenting/Api/Integral/address_list";
    HttpRequest * httpRequest = [HttpRequest sharedInstance];
    [httpRequest postWithURLString:urlStr parameters:parameter success:^(id responseObject) {
        id json = [NSJSONSerialization JSONObjectWithData:responseObject options:0 error:nil];
        self.integralAddressArr = json[@"data"];
        [[NSNotificationCenter defaultCenter] postNotificationName:@"loadIntegralAddress" object:self];
    } failure:^(NSError *error) {
        NSLog(@"%@",error);
    }];
}

//兑换积分商品的接口
-(void)exchangeIntegralGoodsParameter:(NSDictionary *)parameter{
    NSString * urlStr = @"http://112.74.114.1/parenting/Api/Integral/insert_order";
    HttpRequest * httpRequest = [HttpRequest sharedInstance];
    [httpRequest postWithURLString:urlStr parameters:parameter success:^(id responseObject) {
        id json = [NSJSONSerialization JSONObjectWithData:responseObject options:0 error:nil];
        self.succeedStr = json[@"data"];
        NSLog(@"%@",json);
        [[NSNotificationCenter defaultCenter] postNotificationName:@"exchangeIntegralGoods" object:self];
    } failure:^(NSError *error) {
        NSLog(@"%@",error);
    }];
}
//成功界面的接口
-(void)exchangeSucceesParameter:(NSDictionary *)parameter{
    NSString * urlStr = @"http://112.74.114.1/parenting/Api/Integral/suc_info";
    HttpRequest * httpRequest = [HttpRequest sharedInstance];
    [httpRequest postWithURLString:urlStr parameters:parameter success:^(id responseObject) {
        id json = [NSJSONSerialization JSONObjectWithData:responseObject options:0 error:nil];
        self.exchangeSucceedDic = json[@"data"];
        NSLog(@"%@",json);
        [[NSNotificationCenter defaultCenter] postNotificationName:@"exchangeSucceed" object:self];
    } failure:^(NSError *error) {
        NSLog(@"%@",error);
    }];
}

/**----------------------------宝妈商城----------------------------**/
//商城首页

-(void)loadBabyHome{
    NSString * urlStr = @"http://112.74.114.1/parenting/Api/Babymom/index";
    HttpRequest * httpRequest = [HttpRequest sharedInstance];
    [httpRequest postWithURLString:urlStr parameters:nil success:^(id responseObject) {
        id json = [NSJSONSerialization JSONObjectWithData:responseObject options:0 error:nil];
        self.babyAbroadArr = json[@"data"][@"abroad"];
        self.babyCarouselArr = json[@"data"][@"carousel_pic"];
        self.babyClassifyArr = json[@"data"][@"classify"];
        self.babyHomeArr = json[@"data"][@"home"];
        NSLog(@"%lu",(unsigned long)self.babyCarouselArr.count);
        NSLog(@"%@",json[@"carousel_pic"]);
        [[NSNotificationCenter defaultCenter] postNotificationName:@"loadBabyHome" object:self];
    } failure:^(NSError *error) {
        NSLog(@"%@",error);
    }];
}
//点击个别商品的详细页面
-(void)loadBabyDetailedParameter:(NSDictionary *)parameter{
    NSString * urlStr = @"http://112.74.114.1/parenting/Api/Babymom/detail";
    HttpRequest * httpRequest = [HttpRequest sharedInstance];
    [httpRequest postWithURLString:urlStr parameters:parameter success:^(id responseObject) {
        id json = [NSJSONSerialization JSONObjectWithData:responseObject options:0 error:nil];
        self.goodsDetailedDic = json[@"data"][@"goods"];
        self.goodsCarouselArr = json[@"data"][@"goods"][@"carousel_pic"];
        self.goodsStandardArr = json[@"data"][@"goods"][@"standard_pic"];
        self.goodsProductArr = json[@"data"][@"goods"][@"product_pic"];
        self.goodsCommentArr = json[@"data"][@"comment"];
        self.goodsCommentNumDic = json[@"data"];
        NSLog(@"%@",json);
        [[NSNotificationCenter defaultCenter] postNotificationName:@"loadBabyGoodsDetailed" object:self];
    } failure:^(NSError *error) {
        NSLog(@"%@",error);
    }];
}

//加载宝妈商城所有商品信息
-(void) loadBabyAllGoodsParameter:(NSDictionary *) parameter{
    NSString * urlStr = @"http://112.74.114.1/parenting/Api/Babymom/find_all";
    HttpRequest * httpRequest = [HttpRequest sharedInstance];
    [httpRequest postWithURLString:urlStr parameters:parameter success:^(id responseObject) {
        id json = [NSJSONSerialization JSONObjectWithData:responseObject options:0 error:nil];
        self.babyAllGoodsArr = json[@"data"];
        [[NSNotificationCenter defaultCenter] postNotificationName:@"loadBabyGoods" object:self];
        NSLog(@"所有商品%@",json);
    } failure:^(NSError *error) {
        NSLog(@"%@",error);
    }];

}

//加载宝马商城确认订单的接口
-(void) loadBabYOrderParameter:(NSDictionary *)parameter{
    NSString * urlStr = @"http://112.74.114.1/parenting/Api/Babymom/enter_by";
    HttpRequest * httpRequest = [HttpRequest sharedInstance];
    [httpRequest postWithURLString:urlStr parameters:parameter success:^(id responseObject) {
        id json = [NSJSONSerialization JSONObjectWithData:responseObject options:0 error:nil];
        self.babyAdderssDic = json[@"data"][@"address"];
        self.babyOrderDic = json[@"data"][@"goods_info"];
        NSLog(@"宝妈商城%@",json);
        [[NSNotificationCenter defaultCenter] postNotificationName:@"loadBabyOrder" object:self];
    } failure:^(NSError *error) {
        NSLog(@"%@",error);
    }];

}

//提交宝妈商城的订单
-(void) submitBabtyOrderParameter:(NSDictionary *)parameter{
    NSString * urlStr = @"http://112.74.114.1/parenting/Api/Babymom/insert_order";
    HttpRequest * httpRequest = [HttpRequest sharedInstance];
    [httpRequest postWithURLString:urlStr parameters:parameter success:^(id responseObject) {
        id json = [NSJSONSerialization JSONObjectWithData:responseObject options:0 error:nil];
        self.orderIdStr = json[@"data"];
//        NSLog(@"成功后要给我返回orderID%@",json);
        [[NSNotificationCenter defaultCenter] postNotificationName:@"submitBabyOrder" object:self];
    } failure:^(NSError *error) {
        NSLog(@"%@",error);
    }];
}

//从钱包支付的接口
-(void) payForWalletParameter:(NSDictionary *)parameter{
    NSString * urlStr = @"http://112.74.114.1/parenting/Api/Babymom/pay";
    HttpRequest * httpRequest = [HttpRequest sharedInstance];
    [httpRequest postWithURLString:urlStr parameters:parameter success:^(id responseObject) {
        id json = [NSJSONSerialization JSONObjectWithData:responseObject options:0 error:nil];
        NSLog(@"%@",json);
        self.wallectSucceed = json[@"data"];
        [[NSNotificationCenter defaultCenter] postNotificationName:@"payForWallet" object:self];
    } failure:^(NSError *error) {
        NSLog(@"%@",error);
    }];
}

//从微信支付的接口
-(void) payForWechatParameter:(NSDictionary *)parameter{
    NSString * urlStr = @"http://112.74.114.1/parenting/Api/Babymom/pay";
    HttpRequest * httpRequest = [HttpRequest sharedInstance];
    [httpRequest postWithURLString:urlStr parameters:parameter success:^(id responseObject) {
        id json = [NSJSONSerialization JSONObjectWithData:responseObject options:0 error:nil];
        NSLog(@"%@",json);
        self.WXPayArr = json[@"data"];
        [[NSNotificationCenter defaultCenter] postNotificationName:@"payForWechat" object:self];
    } failure:^(NSError *error) {
        NSLog(@"%@",error);
    }];
}

//支付结束后成功界面的接口
-(void)paySucceedParameter:(NSDictionary *) parameter{
    NSString * urlStr = @"http://112.74.114.1/parenting/Api/babymom/suc_info";
    HttpRequest * httpRequest = [HttpRequest sharedInstance];
    [httpRequest postWithURLString:urlStr parameters:parameter success:^(id responseObject) {
        id json = [NSJSONSerialization JSONObjectWithData:responseObject options:0 error:nil];
        self.paySucceedDic = json[@"data"];
        NSLog(@"%@",json);
        [[NSNotificationCenter defaultCenter] postNotificationName:@"paySucceedBy" object:self];
    } failure:^(NSError *error) {
        NSLog(@"%@",error);
    }];
}

//消息提醒的接口
-(void) newsPromptParameter:(NSDictionary *) parameter{
    NSString * urlStr = @"http://112.74.114.1/Parenting/index.php/api/message/remind";
    HttpRequest * httpRequest = [HttpRequest sharedInstance];
    [httpRequest postWithURLString:urlStr parameters:parameter success:^(id responseObject) {
        id json = [NSJSONSerialization JSONObjectWithData:responseObject options:0 error:nil];
        if ([json[@"msg"] isEqual:@200]) {
            self.newsPromptStr = json[@"data"];
        }else{
            self.newsPromptStr = @"-1";
        }        
        [[NSNotificationCenter defaultCenter] postNotificationName:@"newsPrompt" object:self];
    } failure:^(NSError *error) {
        NSLog(@"%@",error);
    }];
}

@end
